% author: Markus Scherer
% renders tab line
% input:  size_out  ... dimensions of output image
%         vlines    ... positions of the vertical lines (first and last are render wider)
%         hlines    ... positions of the horizontal lines 
%         glyph_pos ... 3-by-N array with [y1 x1 index_of_glyph; y2 y2 index_of_glyph;...]
%         glyphs    ... cell array with glyphs
% output: rendered image
function img = render(size_out, vlines, hlines, glyph_pos, glyphs)
  img = uint8(zeros(size_out));
  disp(length(img));
  img(:,:) = 255;

  sh = size(hlines);
  sp = size(glyph_pos);
  sv = size(vlines);
  vlines = sort(vlines);
  hlines = sort(hlines);

  vspan = hlines(1):hlines(sh(2));
  hspan = vlines(1):vlines(sv(2));

  % horizontale linien
  for i = 1:sh(2)
    img(hlines(i), hspan) = 0;
  end

  %dicke Raender am anfang und ende
  img(vspan, vlines(1)+1) = 0; 
  img(vspan, vlines(sv(2))+1) = 0;

  % vertikale linien
  for i = 1:sv(2)
    img(vspan, vlines(i)) = 0;
  end

  %glyphen ins bild kopieren
  for i = 1:sp(1)
    tmp = glyph_pos(i,:);
    y = tmp(1);
    x = tmp(2);
    index = tmp(3); 
    g = glyphs{index};
    sg = size(g);
    img(y:y+sg(1)-1, x:x+sg(2)-1) = g;
  end
